/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author cirulapiph
 */
import java.util.Scanner;
public class ParameterStudentT extends Parameter{
    Scanner input = new Scanner(System.in);
    double hasilIntegral;
    double v;
    double proses;
    
    public ParameterStudentT(){
        //input parameter
        System.out.print("Input batas bawah : ");
        lower = input.nextDouble();
        
        
        System.out.print("Input batas atas : ");
        upper = input.nextDouble();
        
        System.out.print("Input parameter v : ");
        v = input.nextDouble();
        
    }
    
    @Override
    public void integral(){
        hasilIntegral = 0;
        for(double i=lower; i<=upper; i+=0.05){
            hasilIntegral += (i==lower || i==upper) ? F(i) : 2*F(i);
        }
        System.out.println("Nilai pdf = "+0.025*hasilIntegral);
    }
    
    @Override
    public double F(double x) {
        return Tho((v+1)/2)*Math.pow(1+(x*x/v),-Tho((v+1)/2))/(Math.sqrt(v*Math.PI)*Tho(v/2));
    }
    
    public double Tho(double n){
        //System.out.println(n);n
        if( (n-0.5)%2 == 0 || (n-0.5)%2 == 1 ){
            if(n == 0.5){
                return Math.sqrt(Math.PI);
            }else
                return (n-1)*Tho(n-1);
        }
        else {
            if(n==1.0){
                return 1;
            }else
                return (n-1)*Tho(n-1);
        }
    }
    
    public void standarDeviasi(){
        System.out.println("Standar Deviasi Distribusi Student-T = "+Math.sqrt(v/(v-2)));
    }
}
